package cn.edu.gzist.rabbit.service;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service
public class RoutingReceiver {
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("error.message"),
                    exchange = @Exchange(
                            value = "routing.exchange",type = ExchangeTypes.DIRECT
                    ),
                    key = "routingkey.error"))
    public void handler1(String msg) {
        System.out.println("RoutingReceiver:handler1:" + msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("all.message"),
                    exchange = @Exchange(
                            value = "routing.exchange",type = ExchangeTypes.DIRECT
                    ),
                    key = {"routingkey.error","routingkey.warning","routingkey.info"}))
    public void handler2(String msg) {
        System.out.println("RoutingReceiver:handler2:" + msg);
    }
}
